import java.io.FileInputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Scanner;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;


public class ZipFileDemo {
	
	public static void zipFileTest() throws IOException {
		ZipFile zf = new ZipFile("test.zip");
		Enumeration<? extends ZipEntry> entries = zf.entries();
		while (entries.hasMoreElements()) {
			ZipEntry entry = entries.nextElement();
			System.out.println(entry.getName());
		}
		ZipEntry readme = zf.getEntry("ZipFileTest.java");
		System.out.println(readme.getName());
	}

	public static void zipFileDump() throws IOException {
		ZipInputStream zi = null;
		try {
			zi = new ZipInputStream(new FileInputStream("test.zip"));
			ZipEntry entry = null;
			while ((entry = zi.getNextEntry()) != null) {
				if (entry.getName().matches(".*README.*")) {
					System.out.format("%s:%n", entry.getName());
					Scanner s = new Scanner(zi);
					while (s.hasNextLine()) {
						System.out.println(s.nextLine());
					}
				}
			}
		} finally {
			zi.close();
		}
	}
	public static void main(String[] args) throws IOException {
		zipFileTest();
		System.out.println("-----------------------");
		zipFileDump();
	}

}
